package com.pp.tourism.web.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pp.tourism.web.exception.SubmitException;
import com.pp.tourism.web.mapper.UserMapper;
import com.pp.tourism.web.pojo.User;
import com.pp.tourism.web.service.UserService;
import com.pp.tourism.web.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

import static com.pp.tourism.web.exception.ApiRtnCode.LOGIN_INFO_NOT_NULL;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author wjm
 * @since 2019-03-20
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    public List<User> queryUsers(Map<String,Object> param){
        return baseMapper.queryUsers(param);
    }
    public Page<User> queryUserPage(Map<String,Object> param){
        Page<User> page = PageUtil.getQueryPage(param);
        return page.setRecords(baseMapper.queryUsers(page, param));
    }

    @Override
    public User queryUserByUsername(String username) {
        if(StringUtils.isEmpty(username)){
            throw new SubmitException("username can not be null",LOGIN_INFO_NOT_NULL);
        }
        User user = new User();
        user.setUsername(username);
        return baseMapper.selectOne(user);
    }

    @Override
    public User queryUserByName(String username) {
        return userMapper.queryUserByName(username);
    }
}